home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Camelot
/
Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip
/
Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf
/
printfx
/
_main.a
next >
Wrap
Text File
|
1989-06-08
|
3KB
|
80 lines
EOL equ $0a CLI command activator
xdef __main
csect text,0,0,1,2 any xref's after this are 16-bit reloc
xref _main Name of C program to start with.
__main: movem.l d2/d3/a2,-(a7)
*** insert terminators, get pointers, find argc
move.l a7,a2 keep stackpointer
move.l 16(a7),a0 get begin
lea.l 0(a7),a1 remember first argv for reverse action
moveq.l #0,d3 argc (program name)
SrcNSp move.b (a0),d0 search *argv
cmp.b #' ',d0 spaces are delimiters
bhi.s Found any printable but SP causes an *argv
bcs.s FinalT any control causes a leave loop
KillSp clr.b (a0)+ no spaces allowed
bra.s SrcNSp
Found cmp.b #'"',d0 entry embedded spaces?
beq.s SplFnd yes, special search action
move.l a0,-(a7) no, normal, push a *argv
addq.l #1,d3 ++argc
SrcSp cmp.b #' ',(a0) now search for end
beq.s KillSp end found, search next *argv
bcs.s FinalT very end found; leave
addq.l #1,a0 still inside argument,
bra.s SrcSp so keep searching for delimiter
SplFnd addq.l #1,a0 skip special entry code char
move.l a0,-(a7) push a *argv
addq.l #1,d3 ++argc
SrcSpl move.b (a0),d0 only '"' and '\0' are delimiters (EOL?)
beq.s FinalT very end found; leave
cmp.b #'"',d0 special delimiter?
beq.s KillSp yes, act like space found
cmp.b #EOL,d0 @ we look for EOL too
beq.s FinalT @ and leave on meeting it
addq.l #1,a0 no, still inside argument,
bra.s SrcSpl so keep searching for delimiter
FinalT clr.b (a0) now, here is my story:
* If the command line does not contain any embedded space arguments,
* FinalTerm deletes the closing control, normally a LF. However, you are
* allowed to embed all controls but '\0' in embedded space arguments. If
* you do not close this argument with '"', but instead gives an EOL, this
* EOL takes part of this argument. In this version, we leave the loop on
* finding it. (@)
*** The argv-array is in reversed order, so do something about it
move.l a7,a0 get begin, end is already in a1
move.l d3,d2 get number of pointers
lsr.l #1,d2 argc/2 we exchange two at a time
bra.s XPtrs1
XPtrs0 move.l -(a1),d0
move.l (a0),d1
move.l d0,(a0)+
move.l d1,(a1)
XPtrs1 dbra d2,XPtrs0
*** For some reasons its nice to have a long aligned stackpointer.
move.l a7,d1 argv
move.l a7,d0 prepare for long line up
lsr.l #2,d0 we look for a carry
bcc.s LongAl already long
subq.l #2,a7 make a7 long aligned
LongAl move.l d1,-(a7) push *argv[]
move.l d3,-(a7) push argc
jsr _main(pc) Our main is NOT void!
move.l a2,a7 restore stackpointer
movem.l (a7)+,d2/d3/a2
rts
end